import Vue from 'vue'
import App from './App'
import './static/IconFont/iconfont.css'
import requset from 'static/request.js'
import store from './static/store.js'



Vue.config.productionTip = false
App.mpType = 'app'

// 添加请求函数
Vue.prototype.$http = requset

// 添加事件总线
let bus = new Vue()
Vue.prototype.$bus = bus

// 全局创建背景音频播放器
Vue.prototype.$player = uni.getBackgroundAudioManager()


// 定义全局时间格式过滤器
Vue.filter('dateFormat', function (originVal) {
  const dt = new Date(originVal)
  const day = (dt.getDate() + '').padStart(2, '0')
  return `${day}`
})
Vue.filter('monthFormat', function (originVal) {
  const dt = new Date(originVal)
  const month = ((dt.getMonth() + 1) + '').padStart(2, '0')
  return `${month}`
})
Vue.filter('completeFormat', function (originVal) {
  const dt = new Date(originVal)
	const year = dt.getFullYear()
  const month = ((dt.getMonth() + 1) + '').padStart(2, '0')
	const day = (dt.getDate()+ '').padStart(2, '0')
  return `${year}年${month}月${day}日`
})
// 定义全局文本格式过滤器
Vue.filter('textTransform', function (originVal) {
  let text = originVal.replace('↵', '\n')
  return text
})
// 定义全局点赞数过滤器
Vue.filter('likeCountFormat', function (originVal) {
  if (originVal < 100000) {
		return originVal
	} else {
		let str = originVal.toString()
		let sliceStr = str.substring(0, 3)
		return `${sliceStr[0]}${sliceStr[1]}.${sliceStr[2]}万`
	}
})
// 定义全局歌单名过滤器
Vue.filter('songSheetTextFormat', function (originVal) {
  if (originVal.length <= 8) {
		return originVal
	} else {
		let sliceStr1 = originVal.substring(0, 7)
		let sliceStr2 = originVal.substring(8)
		return `${sliceStr1}\n${sliceStr2}`
	}
})
// 定义全局歌单播放数过滤器
Vue.filter('playCountFormat', function (originVal) {
	let str = originVal.toString()
  if (str.length <= 5) {
		return str
	} else if (str.length > 5 && str.length <= 8) {
		let sliceStr1 = str.substring(0, str.length - 4)
		// let sliceStr2 = str.substring(str.length - 4, str.length - 3)
		return `${sliceStr1}万`
	} else if (str.length >= 9 ) {
		let sliceStr3 = str.substring(0, str.length - 8)
		let sliceStr4 = str.substring(str.length - 8, str.length - 7)
		return `${sliceStr3}.${sliceStr4}亿`
	}
})


const app = new Vue({
    ...App,
		store
})
app.$mount()
